local sangliaoxin = fk.CreateSkill{
  name = "lzsj__sangliaoxin",
}


Fk:loadTranslationTable{
  ["lzsj__sangliaoxin"] = "丧僚心",
  [":lzsj__sangliaoxin"] = "出牌阶段结束时，若一号位的手牌数或体力值唯一最多，你可视为对其使用【推心置腹】，否则：你可对一名体力值与一号位相同的角色造成1点伤害，然后直到你下回合开始，你死亡时身份改为平民。",
  ["#sangliaoxin-choose"] = "你可选择一名体力值与主公相同的角色，对其造成1点伤害",
  ["@@sangliaoxin"] = "<font color=\"#45D7DF\">开除党籍！</font>",

  ["$lzsj__sangliaoxin1"] = "敌特名单上画个圈，明天台上少把椅子！",
  ["$lzsj__sangliaoxin2"] = "举报信摞成台阶，正好送老战友上路！",
}

local U = require "packages/utility/utility"

sangliaoxin:addEffect(fk.EventPhaseEnd, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(sangliaoxin.name) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local lord = table.find(room.alive_players, function(p) return p.seat == 1 end)
    if table.every(room:getOtherPlayers(lord), function(p) return p:getHandcardNum() < lord:getHandcardNum() end)
    or table.every(room:getOtherPlayers(lord), function(p) return p.hp < lord.hp end) then
      room:useVirtualCard("sincere_treat", nil, player, lord, sangliaoxin.name, true)
    else
      local tos = room:askToChoosePlayers(player, {
        targets = table.filter(room:getAlivePlayers(), function (p) return lord.hp == p.hp end),
        min_num = 1,
        max_num = 1,
        prompt = "#sangliaoxin-choose",
        skill_name = sangliaoxin.name,
        cancelable = false,
      })
      if #tos > 0 then
        room:addPlayerMark(player, "@@sangliaoxin")
        room:damage({
          from = player,
          to = tos[1],
          damage = 1,
          damageType = fk.NormalDamage,
          skillName = sangliaoxin.name,
        })
      end
    end
  end,
})

sangliaoxin:addEffect(fk.Death, {
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sangliaoxin.name, true, true) and target == player and player:getMark("@@sangliaoxin") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerProperty(player, "role_shown", true)
    room:setPlayerProperty(player, "role", "civilian")
  end,
})

sangliaoxin:addEffect(fk.TurnStart, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(sangliaoxin.name) and target == player and player:getMark("@@sangliaoxin") > 0
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@sangliaoxin", 0)
  end,
})

return sangliaoxin